package com.spingcloud.market.stock.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.spingcloud.market.stock.entity.Stock;
import com.spingcloud.market.stock.mapper.StockMapper;
import com.spingcloud.market.stock.service.IStockService;
import org.springframework.stereotype.Service;

@Service
public class StockServiceImpl extends ServiceImpl<StockMapper, Stock> implements IStockService {
    @Override
    public boolean deduct(Integer productId, Integer num) {
        Stock byId = getById(productId);
        if (byId == null ||byId.getCount() <num) {
//            throw new RuntimeException("库存不足");
            return false;
        }
        byId.setCount(byId.getCount() - num);
        return updateById(byId);
    }
}
